#include <iostream>
#include <jsoncpp/json/json.h>
#include <sstream>
#include <string>
using std::cout;
using std::cin;
using std::endl;


void Serialize()
{
    const char* name="张三";
    int age=19;
    float score[]={85,88.5,99};
    Json::Value test;
    test["name"]=name;
    test["age"]=age;
    test["score"].append(score[0]);
    test["score"].append(score[1]);
    test["score"].append(score[2]);
    std::string Json_str;
    Json::StreamWriterBuilder swb;
    Json::StreamWriter* sw=swb.newStreamWriter();
    std::stringstream ss;
    sw->write(test,&ss);
    std::cout<<ss.str()<<std::endl;
}

void UnSerialize()
{
    std::string str=R"({ "姓名":"张三","年龄":19,"成绩":[100,19,0] })";
    Json::Value root;
    Json::CharReaderBuilder jcb;
    Json::CharReader* jc=jcb.newCharReader();
    jc->parse(str.c_str(),str.c_str()+str.size(),&root,nullptr);
    cout<<root["姓名"].asCString()<<endl;
    cout<<root["年龄"].asInt()<<endl;
    for(int i=0;i<root["成绩"].size();i++) {
        cout<<root["成绩"][i].asFloat()<<endl;
    }
}
    
int main()
{
    Serialize();
    // UnSerialize();
    return 0;
}